﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpTrainer.Objects;
using System.Runtime.Serialization.Json;

namespace SharpTrainer.Util
{
    public class PersonSerializer
    {
        public static Person GetPerson(string jsonText)
        {
            Person person = new Person();
            
            DataContractJsonSerializer json = new DataContractJsonSerializer(person.GetType());
            byte[] binary = System.Text.Encoding.UTF8.GetBytes(jsonText);
            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(binary);
            memoryStream.Position = 0;

            person = (Person)json.ReadObject(memoryStream);

            return person;
        }
    }
}
